package com.b2b.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.b2b.model.CategoryDto;
import com.b2b.model.common.CategoryHot;
import com.b2b.model.entity.goods.Category;
import com.b2b.model.entity.goods.Goods;
import com.b2b.service.goodsService.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.alibaba.fastjson.JSON.parseObject;
import static com.b2b.util.JedisUtil.getJson;

@Component
public class CategoryUtil {
    private final CategoryService categoryService;
    @Autowired
    public CategoryUtil(CategoryService categoryService){
        this.categoryService = categoryService;
    }

    public String getName(Integer categoryId){
        Category category = new Category();
        category.setCategoryId(categoryId);
        Category categoryTemp = categoryService.selectByPrimaryKey(category);
        return categoryTemp.getCategoryName();
    }

    public Integer insert(CategoryDto categoryDto){
        Integer count = categoryService.insert(categoryDto);
        if (count>=0){
            count = categoryDto.getCategoryId();
        }
        return count;
    }

}
